package com.txzt.gaea.business.project.controller;

import com.txzt.base.core.RtnInfo;
import com.txzt.gaea.common.base.controller.BaseController;
import com.txzt.gaea.common.page.PageInfoBT;
import com.txzt.gaea.common.util.StringUtil;
import com.txzt.gaea.provide.dto.FileInfoDTO;
import com.txzt.gaea.provide.model.FileInfo;
import com.txzt.gaea.provide.service.FileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/project/archive")
public class ProjectArchiveController extends BaseController {

    @Autowired
    private FileInfoService fileInfoService;

    @PostMapping(value = "/page/list")
    public RtnInfo<PageInfoBT<FileInfo>> pageList(@RequestBody FileInfoDTO fileInfoDTO){
        if (!StringUtil.isEmpty(fileInfoDTO.getStartDate())){
            fileInfoDTO.setStartDate(fileInfoDTO.getStartDate() + " 00:00:00");
        }
        if (!StringUtil.isEmpty(fileInfoDTO.getEndDate())){
            fileInfoDTO.setEndDate(fileInfoDTO.getEndDate() + " 23:59:59");
        }
        return fileInfoService.pageList(fileInfoDTO);
    }

    @GetMapping(value = "/add/{projectNo}/{fileId}")
    public RtnInfo<?> save(@PathVariable String projectNo,@PathVariable Long fileId){
        return fileInfoService.fileArchiveSave(fileId,projectNo);
    }

    @GetMapping(value = "/delete/{fileId}")
    public RtnInfo<?> delete(@PathVariable Long fileId){
        return fileInfoService.fileArchiveDelete(fileId);
    }


}
